package com.qingzhu.common.domain

import com.fasterxml.jackson.annotation.JsonIgnore
import org.springframework.data.annotation.CreatedBy
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedBy
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.relational.core.mapping.Column
import java.io.Serializable
import java.time.Instant
import javax.persistence.MappedSuperclass

/**
 * DDL
CREATE TABLE xxx (
id int8 NOT NULL GENERATED BY DEFAULT AS IDENTITY,
created_by varchar(500) NULL,
created_date timestamp NOT NULL,
last_modified_by varchar(500) NULL,
last_modified_date timestamp NULL,
CONSTRAINT staff_group_pkey PRIMARY KEY (id)
);
 */
@MappedSuperclass
abstract class AbstractAuditingEntity : Serializable {
    companion object {
        @JvmStatic
        private val serialVersionUID = 1L
    }

    @CreatedBy
    @Column("created_by")
    @JsonIgnore
    var createdBy: String? = null

    @CreatedDate
    @Column("created_date")
    @JsonIgnore
    var createdDate: Instant = Instant.now()

    @LastModifiedBy
    @Column("last_modified_by")
    @JsonIgnore
    var lastModifiedBy: String? = null

    @LastModifiedDate
    @Column("last_modified_date")
    @JsonIgnore
    var lastModifiedDate: Instant = Instant.now()

    /** 机构 ID **/
    var organizationId: Int? = null
}

@MappedSuperclass
abstract class AbstractStaffEntity : AbstractAuditingEntity() {
    // 配置的客服 (每个客服可以有多个配置)
    /** @ManyToOne */
    var staffId: Long? = null
}